package FanShe.factory;

import FanShe.dao.StudentDaoDataBase;
import FanShe.service.StudentServiceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class BeanFactory {
    public static Object getBean(String name){
//        if (name.equals("StudentDao")){
////            return new StudentDaoDataBase();
////        }else if (name.equals("StudentService")){
////            return new StudentServiceImpl();
////        }


        try {
            InputStream is = BeanFactory.class.getClassLoader().getResourceAsStream("bean.properties");
            Properties prop=new Properties();
            prop.load(is);
            String className = prop.getProperty(name);
            Class<?> aClass = Class.forName(className);
            Object obj = aClass.newInstance();
            return obj;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
